<?php

class Core_Model_Permission_Collection_Role extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('permission/role');
        $this->from('{t}permission_role', 'a')
                ->select()->field('a.*');
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'enabled':
            	return $this->eq('a.status', "'enabled'");
            case 'disabled':
            	return $this->eq('a.status', "'disabled'");    
            case 'id':
                return $this->eq('a.id', ':roleId:i')->addParameter('roleId', $arg);
            case 'ids':
                return $this->contain('a.id', ':roleIds:s')->addParameter('roleIds', $arg); 
            case 'idpath':
            	return $this->like('a.id_path', ':idPath:s')->addParameter('idPath', $arg.'%');                      	              
        }
        return $this;
    }

}